//
//  NSError+YZM.m
//  YZMicroStock
//
//  Created by wangminhong on 16/3/22.
//  Copyright © 2016年 cqjr. All rights reserved.
//

#import "NSError+YZM.h"
#import "MBProgressHUD+Utils.h"

@implementation NSError (YZM)

+ (NSError *)yz_errorWithBadResponse
{
    NSError *error = [NSError errorWithDomain: YZNETWORK_ERROR_DOMAIN code: -1 userInfo: @{NSLocalizedDescriptionKey: @"服务器响应异常，请稍后重试"}];
    return error;
}

+ (NSError *)yz_errorWithMessage: (NSString *)message
{
    NSError *error = [NSError errorWithDomain: YZBUSINESS_ERROR_DOMAIN code: -1 userInfo: @{NSLocalizedDescriptionKey: message}];
    return error;
}

- (void)yz_showMessage
{
    if ([self isNoNetwork]) {
        [MBProgressHUD showMessage: @"网络无法连接，请联网后重试"];
    }
    else if ([self.domain isEqualToString: YZBUSINESS_ERROR_DOMAIN] ||
             [self.domain isEqualToString: YZNETWORK_ERROR_DOMAIN])
    {
        [MBProgressHUD showMessage: [self localizedDescription]];
    }
    else
    {
        [MBProgressHUD showMessage: @"服务器响应异常，请稍后重试"];
    }
}

- (BOOL)isNoNetwork
{
    if (self.code == -1009 || self.code == -1004) {
        return YES;
    }
    return NO;
}

+ (NSString *)yz_stringForNoWifi{
    
    return @"网络无法连接，请联网后重试";
}

+ (NSString *)yz_stringForAbnormal{
    
    return @"网络连接异常，请检查后重试";
}


+ (void)yz_showMessageForNoWifi{
    
    [MBProgressHUD showMessage:[self yz_stringForNoWifi]];
}

+ (void)yz_showMessageForAbnormal{
    
    [MBProgressHUD showMessage:[self yz_stringForAbnormal]];
}


@end
